<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:isc="http://extension-functions.intersystems.com" xmlns:hl7="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="isc hl7 xsi exsl">

		
	<!-- 风险章节 -->
	<xsl:template match="*" mode="RiskSection">
		<xsl:apply-templates select="$sectionRootPath[hl7:code/@displayName=$hcc_Risk]" mode="RiskEntry">
		</xsl:apply-templates>
	</xsl:template>
	<!-- 风险章节条目 -->
	<xsl:template match="*" mode="RiskEntry">
		<xsl:apply-templates select="hl7:entry/hl7:observation" mode="HCCAlert">
			<xsl:with-param name="sectionType" select="'RE'"/>
		</xsl:apply-templates>
	</xsl:template>	
	
	<!-- 注意事项章节 -->
	<xsl:template match="*" mode="NoticesSection">
		<xsl:apply-templates select="$sectionRootPath[hl7:code/@code=$hcc_Notices]" mode="NoticesEntry">
		</xsl:apply-templates>
	</xsl:template>
	<!-- 注意事项章节条目 -->
	<xsl:template match="*" mode="NoticesEntry">
		<xsl:apply-templates select="hl7:entry/hl7:observation" mode="HCCAlert">
			<xsl:with-param name="sectionType" select="'NT'"/>
		</xsl:apply-templates>
	</xsl:template>	
	
	<!-- 知情同意章节 -->
	<xsl:template match="*" mode="EducationNoteSection">
		<xsl:apply-templates select="$sectionRootPath[hl7:code/@code=$hcc_EducationNote]" mode="EducationNoteEntry">
		</xsl:apply-templates>
	</xsl:template>
	<!-- 知情同意章节条目 -->
	<xsl:template match="*" mode="EducationNoteEntry">
		<xsl:apply-templates select="." mode="HCCAlert">
			<xsl:with-param name="sectionType" select="'EN'"/>
		</xsl:apply-templates>
	</xsl:template>	

	
	<!--通用Alert条目输出模板-->
	<xsl:template match="*" mode="HCCAlert">
		<xsl:param name = "sectionType" />
		<Alert>
		<EncounterNumber><xsl:value-of select="$encompassingEncounterID"/></EncounterNumber>
		<ExternalId><xsl:value-of select="concat($hccDocNo,'-',$sectionType,'-',position())"/></ExternalId>
		<AlertType>
			<xsl:choose>
				<xsl:when test="$sectionType='RE'">
				<Code><xsl:value-of select="'操作风险'"/></Code>
				<Description><xsl:value-of select="'操作风险'"/></Description>
				</xsl:when>
				<xsl:when test="$sectionType='NT'">
				<Code><xsl:value-of select="'注意事项'"/></Code>
				<Description><xsl:value-of select="'注意事项'"/></Description>
				</xsl:when>
				<xsl:when test="$sectionType='EN'">
				<Code><xsl:value-of select="'知情同意'"/></Code>
				<Description><xsl:value-of select="'知情同意'"/></Description>
				</xsl:when>
			</xsl:choose>
		</AlertType>
		<xsl:choose>
			<xsl:when test="$sectionType='EN' and $hccDocType='C0030'">
			<Alert>			
				<Code><xsl:value-of select="hl7:entry/hl7:observation/hl7:entryRelationship/hl7:observation/hl7:code/@code"/></Code>
				<Description><xsl:value-of select="hl7:entry/hl7:observation/hl7:entryRelationship/hl7:observation/hl7:code/@displayName"/></Description>
			</Alert>
			<Comments><xsl:value-of select="hl7:entry/hl7:observation/hl7:entryRelationship/hl7:observation/hl7:value"/></Comments>
			</xsl:when>
			<xsl:when test="$sectionType='EN' and $hccDocType='C0031'">
			<Alert>			
				<Code><xsl:value-of select="hl7:entry/hl7:observation[hl7:code/@code='DE09.00.117.00']/hl7:value"/></Code>
				<Description><xsl:value-of select="hl7:entry/hl7:observation[hl7:code/@code='DE09.00.117.00']/hl7:value"/></Description>
			</Alert>
			<Comments><xsl:value-of select="hl7:entry/hl7:observation[hl7:code/@code='DE09.00.116.00']/hl7:value"/></Comments>
			</xsl:when>
			<xsl:otherwise>
			<Alert>			
				<Code><xsl:value-of select="hl7:code/@code"/></Code>
				<Description><xsl:value-of select="hl7:code/@displayName"/></Description>
			</Alert>
			<Comments><xsl:value-of select="hl7:value"/></Comments>
			</xsl:otherwise>
		</xsl:choose>
		
		</Alert>		
	</xsl:template>
	
</xsl:stylesheet>
